<?php 
    namespace Activity\Component;
    use DateTime;
    use Application\Component\AbstractComponent;
    
    class ActivityComponent extends AbstractComponent {
        protected  $entity="Activity\\Entity\\Activity";
        
        
        function insert($object){
            $now = new DateTime("now");
            $object->createdAt = $now;
            $object->modifiedAt = $now;
            $this->em->persist($object);
            $this->em->flush();
        }
        
        
        function update($object){
            $now = new DateTime("now");
            $object->modifiedAt = $now;
            $this->em->persist($object);
            $this->em->flush();
        }
        
        
        function delete($id){
            $user = $this->em->find($this->entity, $id);
            $this->em->remove($user);
            $this->em->flush();
        }
        
        
        function get($id){
            return $this->em->getRepository($this->entity)->get($id);
            //return $this->em->find($this->entity, $id);
        }
        
        public function listActivities($adapter, $userId, $fromDate=null, $toDate=null, $filter = "public", $maxResult=null){
        	return $this->em->getRepository($this->entity)->listActivities($adapter, $userId, $fromDate, $toDate, $filter, $maxResult);
        }
        


        public function listFromMax($adapter, $userId, $maxId, $filter, $maxResult=null, $excludeMax=true){
        	return $this->em->getRepository($this->entity)->listFromMax($adapter, $userId, $maxId, $filter, $maxResult, $excludeMax);
        }

        public function listFromMin($adapter, $userId, $minId, $filter, $maxResult=null, $excludeMin=true){
        	return $this->em->getRepository($this->entity)->listFromMin($adapter, $userId, $minId, $filter, $maxResult, $excludeMin);
        }

        
        function listAll(){
            return $this->em->getRepository($this->entity)->listAll();
        }
        
        
        
    }
